#!/bin/sh
alias GETTEXT='gettext "kylin-system-verify"'

user=$(whoami)

if [ $user != "root" ]; then
	: '
	echo "请使用sudo或切换到root用户执行该程序"
	'
	echo "$(GETTEXT "Use sudo or switch to root to execute the program")"
	exit 1;
fi

stay_message() {
	msg="${1}"

	echo ""
	echo $msg
	while true
	do
		sleep 100
	done
}

if [ -f /etc/LICENSE ]; then
	: '
	grep -q "^SERIAL:[0-9][0-9]*$" /etc/LICENSE || stay_message "LICENSE文件无有效服务序列号"
	'
	grep -q "^SERIAL:[0-9][0-9]*$" /etc/LICENSE || stay_message "$(GETTEXT "The LICENSE file does not have a valid service serial number")"

	SERIAL_NO=$(grep "^SERIAL:[0-9][0-9]*$" /etc/LICENSE | head -n 1 | awk -F":" '{print $2}')
	SERIAL_LENGTH=${#SERIAL_NO}
	if [ $SERIAL_LENGTH -eq "6" ]; then
		/usr/bin/kylin-system-verify-legacy
	elif [ $SERIAL_LENGTH -gt "7" ]; then
		/usr/bin/kylin-system-verify-legacy
	elif [ $SERIAL_LENGTH -eq "7" ]; then
		/usr/bin/kylin-system-verify-new
	else
		: '
		#stay_message "LICENSE文件无有效服务序列号"
		'
		stay_message "$(GETTEXT "The LICENSE file does not have a valid service serial number")"
	fi
else
	: '
	#stay_message "无LICENSE文件"
	'
	stay_message "$(GETTEXT "Without a LICENSE file")"
fi
